//
//  SRCatalogueListTableViewCell.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/7/25.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRCatalogueListTableViewCell.h"
#import <NSDate+DateToDisplayString.h>
#import "UIButton+FZGreenButton.h"

NSString *const kSRCatalogueListTableViewCell = @"SRCatalogueListTableViewCell";


@interface SRCatalogueListTableViewCell ()

@property (weak, nonatomic) IBOutlet UIView *borderView;
@property (weak, nonatomic) IBOutlet UILabel *lessonLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *scoreImageView;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (weak, nonatomic) IBOutlet UIView *coverView;
@property (weak, nonatomic) IBOutlet UIButton *deleteButton;
@property (weak, nonatomic) IBOutlet UIButton *doHomeworkButton;

@property (strong, nonatomic) SRBookCatalogueModel *model;

@end

@implementation SRCatalogueListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
        // Initialization code
    
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    
    self.lessonLabel.textColor = css.color_1;
    self.lessonLabel.font = css.fontOfH3;
    
    self.descLabel.textColor = css.color_1;
    self.descLabel.font = css.fontOfH5;
    
    self.timeLabel.textColor = css.color_1;
    self.timeLabel.font = css.fontOfH7;
    
    self.scoreLabel.textColor = css.color_4;
    self.scoreLabel.font = css.fontOfH5;
    
    self.borderView.clipsToBounds = YES;
    self.borderView.layer.cornerRadius = 5;
    self.borderView.backgroundColor = css.color_5;
    
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.coverView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    
    [self.doHomeworkButton applyGreenBackgroundColor];
    self.doHomeworkButton.titleLabel.font = css.fontOfH8;
    
    [self.deleteButton setImage:[UIImage imageNamed:@"common_btn_checkbox"] forState:UIControlStateNormal];
    [self.deleteButton setImage:[UIImage imageNamed:@"common_btn_checkbox_sel"] forState:UIControlStateSelected];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
        // Configure the view for the selected state
}

- (void)updateCellInfo:(SRBookCatalogueModel *)model {
    if (!model) {
        return;
    }
    
    self.model = model;
    self.lessonLabel.text = model.title;
    self.descLabel.text = model.unit;
    
//    NSInteger score = [model.score integerValue];
//    if (score > 0) {
//        self.scoreImageView.hidden = NO;
//        self.scoreLabel.hidden = NO;
//        self.scoreLabel.text = [NSString stringWithFormat:@"%ld", (long)[model.score integerValue] ];
//        if (score > 60) {
//            self.scoreImageView.image = [UIImage imageNamed:@"pass"];
//        } else {
//            self.scoreImageView.image = [UIImage imageNamed:@"unpass"];
//        }
//    } else {
        self.scoreImageView.hidden = YES;
        self.scoreLabel.hidden = YES;
//    }
    
    
    [self.iconImageView fz_setImageWithDefaultPlaceholderWithURL:[NSURL URLWithString:model.page_url] placeholderSize:CGSizeZero];
    self.iconImageView.clipsToBounds = YES;
    self.iconImageView.layer.cornerRadius = 5;
    
//    self.timeLabel.text = [NSDate dateToDetailDisplayStringForTimeInterval:[model.create_time longLongValue]];
    
    
    
}

- (void)setIsSelectedStatus:(BOOL)isSelectedStatus {
    _isSelectedStatus = isSelectedStatus;
    
    [self.deleteButton setSelected:isSelectedStatus];
}

- (void)setIsEditStatus:(BOOL)isEditStatus {
    _isEditStatus = isEditStatus;
    
    self.coverView.hidden = !isEditStatus;
    self.deleteButton.hidden = !isEditStatus;
}

- (IBAction)onDeleteButton:(id)sender {
    if (self.touchDeleteButtonBlock) {
        self.touchDeleteButtonBlock(self.model);
    }
}

- (IBAction)onDoHomeworkButton:(id)sender {
    
    if (self.touchDoHomeworkButtonBlock) {
        self.touchDoHomeworkButtonBlock(self.model) ;
    }
}


@end

